package com.tangyuan.niochat.protocol;

import com.tangyuan.niochat.protocol.serializer.JSONSerializer;

/**
 * Created on 2019-08-28
 *
 * @author fenghongyu
 */
public interface Serializer {

    Serializer DEFAULT = new JSONSerializer();

    /**
     * 返回序列化算法
     */
    byte getSerializerAlgorithm();

    /**
     * java对象转成二进制
     * @param object
     * @return
     */
    byte[] serializer(Object object);

    /**
     * 二进制转成Java对象
     * @param clazz
     * @param bytes
     * @param <T>
     * @return
     */
    <T> T deserializer(Class<T> clazz, byte[] bytes);
}
